home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’93
/
Don's Hacks
/
AppBar Source
/
AppBar.p
< prev
next >
Wrap
Text File
|
1993-06-17
|
4KB
|
140 lines
{
$Workfile: AppBar.p $
$Revision: 1.0 $
A hack that uses System 7.1's Text Services Manager to display a floating pallette of
current running apps
This file is just a very simple application shell. All of the interesting stuff is in
AppBarUnit.p.
© 1993 CE Software, Inc. All rights reserved.
WHEN WHO WHAT
•••••
•••••
}
PROGRAM AppBar;
USES Memtypes, Quickdraw, OSIntf, ToolIntf, PackIntf, MacPrint, AppleTalk, AppleEvents,
GestaltEqu,Folders,Aliases,AppBarUnit; {$R-} {$D+}
VAR doneFlag: BOOLEAN; {set when the user quits the program}
myEvent: EventRecord; {returned by GetNextEvent}
{--------------------------------------------------------------------------
Apple Event handlers
Just handle the required commands. We don't print, so just open files, open the
app, and quit.
--------------------------------------------------------------------------}
FUNCTION GotRequiredParams( theAppleEvent: AppleEvent ): OSErr ; { <aevt> }
VAR typeCode: DescType ;
actualSize: Size ;
err: OSErr ;
BEGIN
err := AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr,
typeWildCard, typeCode, nil, 0, actualSize) ; { nil ok: need only function result }
IF err = errAEDescNotFound THEN GotRequiredParams := noErr
ELSE IF err = noErr THEN GotRequiredParams := errAEEventNotHandled
ELSE GotRequiredParams := err ;
END ; { GotRequiredParams }
Function HandleAEQuit(theAppleEvent,reply:AppleEvent; refcon:longint):OSErr;
begin
HandleAEQuit:=GotRequiredParams( theAppleEvent );
doneflag:=true;
end;
Function HandleAEOpenApp(theAppleEvent,reply:AppleEvent; refcon:longint):OSErr;
begin
HandleAEOpenApp:=GotRequiredParams( theAppleEvent );
DoOpenApp(false);
end;
PROCEDURE InstallAppleEvents ;
VAR
aevtErr: OSErr ; theproc:procptr;
BEGIN
aevtErr := AEInstallEventHandler( kCoreEventClass, kAEQuitApplication,@HandleAEQuit, 0, false ) ;
aevtErr := AEInstallEventHandler( kCoreEventClass, kAEOpenApplication,@HandleAEOpenApp, 0, false ) ;
END ;
{--------------------------------------------------------------------------
Setup
Initialize our managers, Install our AppleEvent handlers, and then init the pallette code.
--------------------------------------------------------------------------}
PROCEDURE SetUp;
VAR i:integer;
numfiles:integer;
templong:longint;
io:OSErr;
p:procptr;
Procedure DoNotRun(io:OSErr; s:str255);
begin
if io<>NoErr then begin
debugstr(s);
ExitToShell;
end;
end;
BEGIN
SetApplLimit(pointer(ord4(GetApplLimit)-32768)); {give an additional 32K to stack}
MaxApplZone;
InitGraf(@thePort); {still need QuickDraw}
doneFlag := FALSE;
{See if we can do AppleEvents}
io:=Gestalt(gestaltAppleEventsAttr,templong);
if io=NoErr then if not odd(templong) then io:=-1;
DoNotRun(io,'Apple Events not installed');
InstallAppleEvents;
DoNotRun(InitLayer,'Unable to initialize our Layer stuff');
END; { of SetUp}
{--------------------------------------------------------------------------
MainEventLoop
Handle our events. As a background app, we don't do much, do we?
We also call the pallette code's idle routine here.
--------------------------------------------------------------------------}
PROCEDURE MainEventLoop;
var dummy:boolean;
io:OSErr;
BEGIN
REPEAT
SetCursor(arrow);
dummy := WaitNextEvent(everyEvent,myEvent,$7FFFFFFF,nil);
CASE myEvent.what OF
kHighLevelEvent:
io:=AEProcessAppleEvent( myevent ) ; { <aevt> }
END; { of event case }
LayerIdleProc(doneflag);
UNTIL doneFlag;
END;
BEGIN { main program }
SetUp;
MainEventLoop;
CloseLayer;
END.